Moved HTML cleaning function to its own module

Also includes tests.