factor out attribute accessor code