Refactored base.js