replace os.system with subprocess
some bug fixes