Additional fixes and some code cleanup