made uploading to db faster and cleaned up code