improve the code according to Vlad's review