major refactor, still bugs