Various fixes. Add entity tests