Fixed tests and cleanup of Java code