improved comments and small structural tweaks.