Improve algorithm for results calculation