first version from my old codes