adding defensive code, and one more macro for buffer size