optimized logic code for show and hide
optimized code