Converted sqlite3 loop to remote call