need to improve this code