Ready to be submitted

Fixed a division by 0 bug and optimized a little.
Also commented and added 3 test cases in the beginning (required by
prof)