Lots of cleanup

removed a bunch of unused variables, cleaned up exception handling.