Re-factor definitions and tests