Bug fixes, error handling