Added docstings. Made refactoring.