Based on Michael Hartl's tutorial.