first working version, thanks Emanuel for the help