Eliminating the pyramid of doom in Javascript