i think all the package importation should be done at the beginning of the code..otherwise this should work but try to separate importation from the actual code..