much cleaner version of P14.hs