Added comments, refactored