improved a bit the code