dry principle and a few fixes.