Fix problems and make it compile in java (prevously in groovy)