Replaced some helper functions with case-clauses for better readability