refactored startup logic