refactory stack creation