Commented, refactored, and added more unit tests