substituted switch statements with if/else, formatGrid function now works