Refactor and scheduler