Remake frame drawing math to be much more reliable