calculating generations