wrap code with 'main' function
refactor
refactor; fix buffered frame number accumulation