some more refactorying and bug/typos fixes.