Moved some logic from app delegate.
Some more cleaning.
Whoops.