Move decode frame to separate function