refactored to java