Final refactoring

final commit with some refactoring done