Refactor, final version