Rewriting the gradient functions to fetch the picture only once