Fix bugs in cleanup command and Flask app config