Refactoring code and removing duplicate methods