add support for flashing along with better error handling