Changes from Boris' code review, thanks!