moved helper error throwing to the end of file