refactor + optimize