Worked on #75. Sacrificed implementation complexity for better error messages.