Cleaned up, modularized and added tooltip.

Please have a look at this. I have tried to make it modular and debug-able, which could be handy in future.