Sort doc items before using them
Fixed event category param parsing issue
Moved time gen function aronud