new error handling and small structuring changes to fit traitlets format