Lots of internal fixes & changes. Added error handling and caching logic.