first working version and done a format of the code