improved the jquery to work more logically and faster too