This PR reworks several parts of the PR.
This means a bunch of breaking changes, including const removal from some functions. The latter is unfortunately necessary because some implementation details changed or may change, and I wouldn't be able to guarantee the const qualifier.