Refactored, removed all the junk left behind from previous attempts.