WIP: optimization still contains bugs, but now playable.