largely finished - still needs to output text files