Renamed some variables for clarity, added comments and function titles, only return values when necessary.