[UNSTABLE] Multiple improvements and refactoring