Changed order of getting objects to avoid exception