tried to improve the code