Cleaning up repeated code