Some error handling, cleanup