Fixed some bugs and let script keep existing configuration