Added documentation, Improved caching and some refactoring