Fix crash and move Main method