cleanup and add debug option