trimming function improved, doesn't kill data noise