refatoring to better use jquery