Fixes and error throwing refactoring