Did some modularised the code a bit.