Added exceptions and small fixes