refactor allegro.js