program redesigned and simplified
speed increased