Small changes and refactoring, still WIP