code cleanup + extra test