tidied up code and added elk index support