Refactoring again, not happy with mess before