Code review

Refactoring and code deduplication with @bellarose94 @cmisenas