Opensource cleanup

 - Refactored the code
 - Code is in accordance with PEP8
 - Added comments
 - Added caching