Made major changes and tried to implement it. This is incomplete and needs a lot of cleanup