improving speed code