Fixed bug caused by masked reference database.  Other small fixes