refactor and cmake support.