converted if-else statements to switchfor better speed and readability