fix calculating bug