changed algorithm