This is a very useful code! Would you point out the reference where the implementation is based? Thanks!