Imroving error handling