cleaned up repeated code.