tracking parents, error handling, and general refactoring