Added checking for empty state before executing commands