use a guard instead of case statement and shorten some clauses