Code cleanup and Mysqli Update

A buggy Mysqli update and a huge code cleanup