bug fix -- order of callig methods changed to avoid null-pointer exception