Move most of this stuff to Java code.