Refactored p21.hs