SQL query update
Added more unit tests and documentation