Refactored code for using intefaces.