Refactored some functions and updated documentation