Make sure invalid statements are caught

Closes #231