misc fixes and refactors