removed ifs via pattern matching, but names of functions have to be reviewed