Improvements to WHATraq code originally by Cong Zhou