Changed loader to use while loop