improved analyze script