new approach with states (so errors could be returned)