Merged code from Bittorent Sync