bugfix in eliminating invalid chatracters