Cleanup app code; separate into private methods.