added missing comma, and some refactoring.