Refactor and retab primegen.hs