Java port by Alex Olwal