improve the code a bit