enhanced debugging and error handling