code clean up and write to db