-Added basic threading facilities for main loop management