Assign and access variables more cautiously

Per @dtrebbien's pull request.