refactor and add more descriptive errors