Cleaned up code, fixed functions and added overwrite, open capability fixed