restored frame decoding code with bug fix for better performance