Remove repeated code logic

Bug https://bugzilla.gnome.org/show_bug.cgi?id=740176