First fully functional version (run untested)