added folder checking algorithm