organized code, added convexity test