Some sanitization

Clean up, error handling etc