complete rewrite of overscan.c