Bug fixes from Marek's comments.