code cleanup and fixing a few syntax errors