Fixed CPU consumption bug in main