Implemented calculating function