Refactor Prob012.hs.