All of these functions have the same general shape; perhaps a macro generating them would be handy?