added original code, including ensemble analysis