better algorithm for activity