reworked some code to prepare for unit tests