Add errorOn and refactor