Cleanup

- Split up the affine bg pixel fetching.
- Added more boundary checking.
add more type guards