Merge two bug fixes from master