Remove unused test code
Fix a few code errors