Corrected syntax errors and minor refactoring.