big refactor looking a lot better now