Various bug corrections