Imrpovements for index.js

Return when we can, safer and we can prevent some indent.