changed some variable scoping and improved selector usability