create new Main.hs and refactor code; improve error messages