animation loop and some basic functions