Added logic to emit errors when they are encountered