Please make the code a macro of sorts to reduce the duplication.