source code for cirrus and related script, not refined yet