Fix and refactor