Please consider to use closure here instead of declaring two new functions every time.