generalizing and minimizing code