Fixes for Trac #1497, 1499 and 1500