added flash memory space check