Streamline java code