bug fixes + unit tests fixes