Use timer instead of ugly while()