Replace anonymous classes with private inner class