made value calculation recursive