tested with static analyzer

made changes according to performance suggestions using static analyzer