Refactored compare stage. Refactored file open functions.