Make some code a bit more elegant

No functionality changes, just made a few lines more concise.