this is a lot of math... but i'm making good progress