Code refactoring of chef.js