added while loop and return stmt