Some changes to sql and added some (maybe) useful classes