iterative version. Not complete