Abstract the code a bit by using functions