better exception handling; refactor for file and string input
preliminary unit-test