Refactor and test Analysis module