Thank you for your reply Mr. Lichtblau. I apologize for all the mistakes. I will follow up on your suggestions and post the complete code in the future.
In the meantime, I have managed to get the program to work by setting up a grid of values of y[x] and x using FindRoot to populate the grid with values g and then create a 2D InterpolatingFunction . I replace the g function that calls FindRoot directly by the InterpolatingFunction. It feels like a kluge to me, but it works.