Fixed bugs, added some atomic updates.