modified cleaning function. Fixes #5