Added invalid character check