without recursion