Code refactoring

Better startup handling