refactored code using slideUp and slideDown methods