simple core algorithm