sql codes cleaned up