Increase DB performance, fixed race condition w/ segfault

- Use prepared/cached DB statements
- Lock/unlock the blockQueue because threads