added code to prevent lost flash