some refactoring, added a record class, finalized output format
some small convenient script changes