applied Matt's patches