linux version (rewrite in Python)