fix some issues with pixel overflow

TODO: edge handling