first part done
error checking in place
small fix