Added volume envelope classes + code cleanup

Also added unit test.