Make application main only
Fix main so that it is better for threading?