Redesigned timer handling

Redesigned because of thread problems.