refactored the implementation of head.js