Added comments and contracts to the code. Also included the existing javadoc generated in my session.