added timer (unstable)
rearanged some functions