make some methods static; replace recursive call