Speeded up the code