maintaining state and creating correctly