some refactoring-related comments
fix error handling