Some serious refactor