Imported from dropbox with refactoring code into 3 files
Made even more changes.
More changes(i think)