Made some code a bit dryer