wavwout works better
code is very dirty. needs deep refactoring