Add logging, more robust, self contained