Fixed some exception handling