Previous code was running into seg fault.

Made a lot of changes using prof's help.