added another application of state monad and changed function names