Various fixed and refactors