Added parameters and implemented use of window.requestAnimationFrame

Thanks @Coornail for the feedback!