Even more fixes and refactors.