Improve mysql queries and handling
Fixing merge conflics. Closes #8 :+1: