Some code cleanup
should be easier to maintain now