almost finished categorize function
some sql function left