Remove some duplication
fix (most) pmd warnings on unused local variables