Working solution without comments