Added comments, cleaned up code, added default formatting for eclipse.