Clean code. Sort of.

Some code correction, more pythonic)

BTW, i think source should be separated because now code looks really messy.