Got a basic algorithm figured out