refactored ALSA by extracting some methods into easier-to-understand chunks