refactored using JQuery