A more robust implementation for the init script