Exception handling, some debugging changes. Added session.