Mainly bug fixes