Simplified some arithmetic and fixed some bugs when using negative display windows.