Filling out the logic a bit more, fixing things.