First working version
Small optimize