refactored for readability(!) and added a couple more tests for the last 2 frames