First working version... some bugs, but work.