Added local scoping and fixed trailing commas/semicolons