Added lots of error trapping