better commenting of the logic here