replaced console.log hack with cleaner solution