Added some exception hanlding