cleaned up some functions, swapped ifelse in main to switch case