fix some bugs
clean code
Merge pull request #3 from michaelnsj/FIX_ES_BUGS

Merged.