Working solution without comments.