Cleanup pattern building function