added debug empty() check