refactor to requst animation frame