Refactor and comment the startup code