fixing replace on undefined
documenting clean function