fixing exceptions and bugs.