Re-write for Java backend