Move code to main form