Add syntax checking, better errors, refactor