fixed a few bugs, and added comments on all functions
Fixed minor bugs and added comments to every function