correct logic error, also add one more debug func