changed order of checks, to ensure most logic error gets thrown first