refactored, added some java docs