cut down on the number of loops, and fixed bug where a select list was displayed when it shouldnt have been