Added locking on thrift calls, and overall cleanup