added old code, converting to java