Refactor MainActivity

Used some sample code from http://pastebin.com/J4uDgrZ8, retrofitted to our purposes