Several tweaks and refactors