Final updated code. Submitted to app store.