Add --release and related refactoring