Moved the code responsible for management of external resources into a seperate method