type exceptions and cleaning up code