Improved logic for buttons to show/hide.