I wish there were a more compact way to write the above three functions without all the duplication. How about convert these to a macro?