computation is done recursively now. Thanks to Pekka