Add some error handling, improvements