cleaning up code, working on "invalid character" restriction