small code cleanup/generalisation