Added better exception handling

Still not good.