Added an option for the where clause and other clean ups