improve error handling, fix registration