added main timing loop