added extra comments, changed 'level' to 'layer', and corrected direction of rotation (was previously anti-clockwise)