mild refactor; adding const when appropriate
more refactor