Optimize the code a bit