fix a few calculation issues