add foreach fcuntion and free function