Bug correction

Inproved error handling