Moved application startup stuff into library function