improvings and error handling