switched "cond"s by "case"s to tidy up the code a bit