* Use pattern matching instead of where
* Compute length of list only once and use case expression
to better express intent.