Fixed several ugly bugs in the sound code