After googling around and reading, I found the code below. Problem is, it\'s been a few weeks and I\'ve lost the original post.
I have now done my best in understandi