Debugged issues with some errors being reported multiple times, and with undeclared variables not being properly handled. Added test for both cases.