Full refactor into some modules