refactored main loop and time functions
time functions improved on render loops
code safety
added a function to get an element offset