rewrote code to use more jQuery
also added comments