Handle exceptions so it doesn't crash