Documentation added. Better error handling