tried to improve code quality

hope I did not mess up too much, need to test a bit.
My plan is to create some automatic tests, too. Hope I'll get
to that.. should help development a lot.