adding query for to_userid
removing unused code.