Refactor and error messages