moved calcs into each loops