Refactoring eggman.js