move locking and transaction down so we don't sleep with the lock while waiting to clean up old data #115
change while loop to for loop #115