Bugfixes to Refactor

Bugfixes.