Use before_first_request instead of starting thread in main to avoid double threads