Fixing bug when working with mysql db