Reorder checks to prevent malformed packets throwing errors