Added test coverage, fixed bug when assembling MySQL output