improve script speed, refactoring quesries, add per app queries, change data structure, change appsession length calculation