Changed queries to work with views, instead of temp-tables.