refactored code into an adapter like implementation