Added some docs, some refactoring