Finally fix logic. Fixes #378.