Added some exception handling

- Its stil not perfect though