Implemented most logic.

Seg faults --> need to fix.