nicer code; fixed bugs with deleting and opening files