Changed loop to check boolean variable instead of running forever