Basicially avoid nested functions / callbacks. Event emitters and prototypes can help here.