Merged bug fixes from master.