Refactor & Code Coverage for Algorithm