Refactored mysql a bit, other tweaks