Improved error checking and added a test for brace-pop