Review comments applied
Merged with error-handling