Cleanup + error catching + adding function declarations to grammar.