implement Earley parser and some code cleanup
cleanup code