use flag instead of function to check open devices