Added exceptions, still pretty naive though.