New, tested version of analysis script