why do you look for this elements twice inside functions? Instead you can make them more global