Fix broken compilation & logic bug

The last commit broke compilation. This fixes it. Also fixed a logic bug introduced in the same commit. Compilation will still be broken -- one more fix to follow.