some refactor to not define variables several times