Moves some logic that deals with manipulating data into model functions, cleans up code and comments
Merge remote-tracking branch 'origin/master'