more fix and refactors