Fixed sql and moved populate queries to another file