Clean up main task running method. Expand tests.