moved sums to sql - works perfect