Refactors power function, separates commandsMap into a reusable object