updated code to use Attempt