fixed function dependencies
corrected file insertion function