reduce unnecessary procedure from loop
fix undefined notice