fix type errors & finish refactoring