modified a little for debug message
modified to skip state != 1
medified to fix logging method