added error handling (Either and ErrorT monads)