more efficient digit checking