refactored tinfoil.js and extracted returned function