bug fixes: some issues remain, need more discussion later
bug fix
bug fix for loop rule