More refactoring and resolve some TODOs