First version of improved code