refactor mostly done