Moved while loop outside of try...catch (will always continue even if there is an error)