moved calculations out of the request animation frame