Extracted logic into inner class for testing