extracted all main functionality into private functions and wrapped them in locks and unlocks, effectively creating a monitor with a condition on the size of the list.