javadoced and cleaned up some messy code