Replace add_to_log calls with relevant events
Replace userfield queries with get_all_user_name_fields and fix minor warnings