Cleaned up analysis code