Removed locks and some if statements to improve performance