Various fixes
Fix for issue #1287