Fixes db insertion problems. Speed is still an issue though.