more comprehensible implementation