solve recursion with flag - not good (ToDo: improve!)