fixed regression in unit tests introduced in previous commit and further cleaned up the code.