Refactoring:Added the code to the wrong function