Abstract the code a bit