Added counter-clockwise flag.
Minor refactoring.