Fixed proc to work recursively