changed data structure and added Pair inner class