Added JSDoc comments and cleaned up