rewrote once more for code clarity