code cleanup, more comments, more javadoc