Fix layouts
Optimize queries with inner join