cleaned up code
fixed charorder bug
added unit test