added/tested caculate function