added specs, updated algo