Code it working, and comments added. Bugs are listed under function names.