Working solution for the first question of the project