refactored program, updated javadoc