implemented some changes suggested by find bugs inspecton