Lots of cleanup / improved exception handling