Check the original post, I have updated the code. Plus provided a working example.