Small fixes and tunning MySQL performance