use better database iteration method, change function naming