Added comments. Refactored into two files.