Refactored code

- The file is flatter now. Because flat is better than nested.
- The processing ends when the file has no more frames.
- try/except blocks were removed with more readable code.