did some refactorings based on comments of previous PR