complete the function of statefull