DW: Code cleanup and test