fixing some failed unit tests, and some code quality issues