make it more robust, some additional checks and warning messages added