Included many fixes and improved wav file writer