added fix for AMQ-883 and AMQ-865 along with test cases from Denis Abramov and Bryan Schmidt. In partcular many thanks to Bryan Schmidt who figured out what the problem was and helped me do wacky things with the event delegate thingy :)