I understood the code is not really scala code, but more translated Java code. What would be a good way to rewrite it?