Attempt at fixing function not loading properly