Refactoring some Javascript.