A working version just needs some touching up, deleted the test main methods