java version working (although disappointingly just as slow)