Initial isLegal function.

Not completely done, will try to work on when I have the time.