Kleene star implementation not working