Fixes and refactors, using console.error instead of throw everywhere.