bug and style fixes
merge conflicts