Refactor the code a bit.