need to improve

function not so beautiful...