Use a macro to cut down on duplication of code

This PR addresses #6.