Added some functions and commentary, refined some names