Wrote most of the folder montitoring function