fixed macro bug that could result in ill-formed code and added test cases