fix a bunch of code quality issues