Working program. Needs to be tested against test files
fixed merge conflict