Refactoring and removal of redundant code