got rid of do notation everywhere; altered 'readProgram' to ensure wellformedness of any accepted program; added calls to 'error' in cases that ought to be impossible if 'readProgram' is correct
added comments for clarity