re-ordered document so there are no misplaced declarations
cleaned up rule dialog