Added comments into the code for readability
Reordered funcs so it was below its type