added more error handling to factory methods