Refactor slightly to make it faster