Based on raywenderlich.com swift tutorial