Several functions added, still working on is_legal function.