switch on latedef option and fix issues. Fixes #1521