Lots of commenting, moved funcs to where they should be to make for easier reading