removed duplicate code and included required import os