Refactored init() function (logic)