const + some refactoring