Incorporated suggestions from Dimitri Papadimitriou