Finished refactoring. Compiles and runs.
Now it needs testing, because it's quite likely to crash.

Signed-off-by: retep998 <retep998@verizon.net>