Added and organized a bit of the code