Code clean-up and removal of duplication