Implementing all_same_color function