Re-arranged some code to avoid unnecessary web request being performed when
not needed