Refactored to use Java instead of the Processing dialect