Added error handling for bad scan