Modify prime_numbers function to use outer loop