Working, but still to refactor slightly