updated with a try/catch loop to prevent crashing on sql exceptions