Bug fixes around open(), and a few logic fixes.