cleanup duplicate code popularity
apply time filtering to max count as well

the join for max count is very very slow..
close session and avoid unneccessary query