more refactroing, plus fixes