improved analysis script