Also makes some functions const, and use them instead of accessing variable directly
Follow up to 999a24c3 Fix #1270 (closed)
Follow up on !3755 (merged), annoyingly I only noticed when I went to retest the issue before closing. Requires adding a new function.