Py3k

I have done some refactoring to adapt into py3k.

Some refactorings also improve py2k version too. Especially dotted relative import change is important.

Tested on python 2.7 and 3.2 .