Refactoring code to seperate elements