moved writewave method inside save event