refactering a debug code