Fix clean rules algorithm. Add commented console log messages for debugging.