Merged code , everything works fine, still need to handle errors
(implement some error routines)