Misc bug fixes - null pointer exception in edit environment etc