added some safety check at the very beginning
improved description