greatly improved speed by just solving via math