Move loading playlist code to separate function