Improved return object and building of SQL