Refactored and added debug statements in preparation for Issue #2