adds recursive function