Refactor analyze method