Giving some shape and using some code from Python implementation.