reworked some solutions with pattern matching