Added error management, minfixes