Small DRY tweaks

In my adventure of trying to fix #19 I've noticed that there are some parts that are repeated. 

I had some spare time and, with my limited python knowledge, i tweaked a little parts of the code that i saw is repeating.