Factored out main application code into its own object, and added Next/Previous support