Refactoring and fixing docs