Revised
Added error checking and error window messages