Moving function into a proper location. Also fixing a tiny bug with one row result return.