changing lots of if() by switch()