Refactored some code and added full elasticsearch module test suite