Move code to namespace and add debug mode.