Updated with merge code from Anthony

Sound needs debugging.