style fixes and some logical issue