Refactoring after review

Mostly removed .size() calls and added consts.