Fixes and refactors