integrated robin's code

added to all main 3 files, shall test tomorrow that all the SQL/result
set stuff is working