Fix bugs introduced in previous commit

Commit 14e4847d5986cd83f295dbcc66a97968fa1c4145.