Based on the ruby tutorial by Michael Hartl