code redundancy reduction, courtesy of suxen_drol -at- hotmail.com