Added some help/explanations. Split some functions to separate file.