Copied over noise removal function