initial rewrite of display algorithm. more changes are planned.