fixes and refactors