Bugfixes, compacted code

Changed the procedures to use get_ir_sql to get rid of double code