Made the code a lot nicer. Thanks pingou