Copied code from all 3 versions in