First working version of script