Phase scrambling, magnitude averaging, magnitude replacing moved to separate functions