wip refactoring for better error messages
better error reporting