Made exception handling better.