Added constants to functions, updated SQL