Refactor frame.js