fix potential sql injections
small drying
Sort cleanup.