Move code to a function