moving low level debug code to more appropriate location