Fixes bugs, this version actually works as intended