first night of work, mostly added auxillary functions