renamed functions and improved comments and javadoc