ENH : refactor CSP code