better error codes, cleaner file manipulation