Added writeback to database for submission and fixed bug with extra results