Added error handling so it doesn't crash so often