pattern matching instead of bunch of clumsy if/else statements