Minor fixes to syntax and error handling