optimize a bit of code