Retooled mysql queries; cleanup.