Moved chart data calculation to a service and some other fixes