Added exceptions and changed main