Added error logging

And some try catches