convert the error checking to macros for succinctness