Improved code and fixed problems with clone