Improve Python version

* Clean python code (encapsulate into functions)
* Make it compatible with Python3 and Python2
* Add a rule to run test with Pypy in Makefile