first solution tested and working. Better one coming up