I bet you can easily merge this if with the one above and do it more beautiful, without code repeating.