commented and refactored, added cv window option