refactor, got rid of that messy pointer madness