refactored file saving/fixed bugs