Moved context switching in main loop
Problem: The context was set in the main loop just prior to the event
offloading. This yielded the problem that it was not set correctly
during determination of event durations thus picking the duration from
Solution: Moved context switching prior to duration determination.