added improved ecdf code