several small changes and addition of unit tests