Serveral bug fixes.