debugged calculation issue