functions for analysis code