Reverted to var f func.. since the functions are executed recursively, it was undefined when initialized with :=