Heavy refactoring of battlemap.js