mostly style issues; some potential memory issues fixed