Refactored main code a little. Added very basic/unfinished tests.